{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c2ec89ec",
   "metadata": {},
   "outputs": [],
   "source": [
    "import datetime as dt\n",
    "\n",
    "from gs_quant.data.fields import DataMeasure\n",
    "from gs_quant.markets.index import Index\n",
    "from gs_quant.session import Environment, GsSession"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9eb4d9e4",
   "metadata": {},
   "source": [
    "## Pre Requisites\n",
    "To use below functionality on **STS Indices**, your application needs to have access to the following datasets:\n",
    "1. [STS_FUNDAMENTALS](https://marquee.gs.com/s/developer/datasets/STS_FUNDAMENTALS) - Fundamental metrics of STS Indices\n",
    "\n",
    "You can request access by going to the Dataset Catalog Page linked above.\n",
    "\n",
    "Note - Please skip this if you are an internal user"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "de70c758",
   "metadata": {},
   "outputs": [],
   "source": [
    "# external users should substitute their client id and secret; please skip this step if using internal jupyterhub\n",
    "GsSession.use(Environment.PROD, client_id=None, client_secret=None, scopes=('read_product_data',))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f384ea49",
   "metadata": {},
   "outputs": [],
   "source": [
    "index = Index.get('GSXXXXXX')  # substitute input with any identifier for a single stock STS index."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d619009b",
   "metadata": {},
   "outputs": [],
   "source": [
    "index.get_fundamentals() # default period is one year, default period direction is forward, default metrics are all available metrics"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8c98e5fc",
   "metadata": {},
   "outputs": [],
   "source": [
    "index.get_fundamentals(start=dt.date(2021, 1, 7), end=dt.date(2021, 3, 27))  # get fundamentals for the specified date range"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e4024bc8",
   "metadata": {},
   "source": [
    "You may choose one of the following periods:\n",
    "\n",
    "- **1 year:** DataMeasure.ONE_YEAR\n",
    "- **2 years:** DataMeasure.TWO_YEARS\n",
    "- **3 years:** DataMeasure.THREE_YEARS\n",
    "\n",
    "You may choose one of the following period directions:\n",
    "\n",
    "- **Forward:** DataMeasure.FORWARD\n",
    "- **Trailing:** DataMeasure.TRAILING"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b2257277",
   "metadata": {},
   "outputs": [],
   "source": [
    "index.get_fundamentals(period=DataMeasure.TWO_YEARS, direction=DataMeasure.TRAILING)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "369b0fed",
   "metadata": {},
   "source": [
    "You may choose any combinations of the following metrics:\n",
    "\n",
    "- **Dividend Yield:** DataMeasure.DIVIDEND_YIELD\n",
    "- **Earnings per Share:** DataMeasure.EARNINGS_PER_SHARE\n",
    "- **Earnings per Share Positive:** DataMeasure.EARNINGS_PER_SHARE_POSITIVE\n",
    "- **Net Debt to EBITDA:** DataMeasure.NET_DEBT_TO_EBITDA\n",
    "- **Price to Book:** DataMeasure.PRICE_TO_BOOK\n",
    "- **Price to Cash:** DataMeasure.PRICE_TO_CASH\n",
    "- **Price to Earnings:** DataMeasure.PRICE_TO_EARNINGS\n",
    "- **Price to Earnings Positive:** DataMeasure.PRICE_TO_EARNINGS_POSITIVE\n",
    "- **Price to Sales:** DataMeasure.PRICE_TO_SALES\n",
    "- **Return on Equity:** DataMeasure.RETURN_ON_EQUITY\n",
    "- **Sales per Share:** DataMeasure.SALES_PER_SHARE"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "37118eed",
   "metadata": {},
   "outputs": [],
   "source": [
    "index.get_fundamentals(metrics=[DataMeasure.PRICE_TO_CASH, DataMeasure.SALES_PER_SHARE])    "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "55047ebb",
   "metadata": {},
   "source": [
    "*Have any other questions? Reach out to the [Marquee STS team](mailto:gs-marquee-sts-support@gs.com)!*"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}